home *** CD-ROM | disk | FTP | other *** search
- Path: cs.ruu.nl!usenet
- From: wsldanke@cs.ruu.nl (Wessel Dankers)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Random Number Generation
- Date: 20 Feb 96 23:52:58 +0100
- Organization: Dept of Computer Science, Utrecht University, The Netherlands
- Message-ID: <2108.6624T1432T2901@cs.ruu.nl>
- References: <199602071623.QAA00075@sable.ox.ac.uk> <Pine.OSF.3.91.960207175121.20357B-100000@hai.hiMolde.no>
- <19960207.41F660.11A72@aj050.du.pipex.com> <1100.6613T1273T666@himolde.no>
- <692.6619T1254T1752@in.net> <4g2bi9$1fls@rs18.hrz.th-darmstadt.de> <19960220.7D62838.7EC3@mojaveg.ridgecrest.ca.us>
- NNTP-Posting-Host: anx1p5.cc.ruu.nl
- X-Newsreader: THOR 2.22 (Amiga TCP/IP)
-
- >> #include <stdlib.h>
- >> ....
- >> num = ( (float) rand() / 32767E0 ) * ( high - low ) + low;
-
- >In theory, this is a very good suggestion. In practice, rand() is a
- >very poor RNG. Run any common statistical tests on rand()'s output
- >to see.
-
- What's wrong with FastRand()?
-
- From a totally unexpected corner I got this article, which, amongst a lot of
- stuff about why god doesn't exist, contained the following algorithm as an
- *example*, so I don't know how good it is. (layout slightly changed by me).
-
- --
- From: PAGAN <pagan@delphi.com>
- Subject: Re: Atheism; the perfect antidote to poetry and style.
- Date: Sat, 10 Feb 96 04:15:01
- Newsgroups: alt.atheism.moderated
-
- /*********************************************************************
- RANDOM number generator
- returns a random number from one to the value passed
- repeat rate OTO 1e6
- *********************************************************************/
- int random(int val)
- { int num; /* this is what will be returned */
- int bit0, bit1, bit14;
- static int rndval=2; /* seed value */
-
- if(val<0) /* if a negative value passed */
- rndval=-val; /* reseed */
-
- bit0 = rndval & 1;
- bit1 = (rndval & 2) >> 1;
- bit14 = bit0 ^ bit1;
- rndval >>= 1;
- rndval |= bit14 << 14;
-
- num = rndval % val;
- return num ? num : val;
- }
-
- /*********************************************************************
- SEED the RANDOM number generator
- random number seed for the above
- *********************************************************************/
- seedrandom() /* negative value to seed the generator */
- { random(-systemticks()); /* seed with system tick count */
- }
- --
-
-
- --
- Wessel Dankers _\\|//_ <wsldanke@cs.ruu.nl>
- ///|\\\
- ----------------------------oOO--(_)---OOo----------------------------
- `Never imagine yourself not to be otherwise than what it might appear
- to others that what you were or might have been was not otherwise than
- what you had been would have appeared to them to be otherwise.'
-
-